﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class EnemyWave
{
    public WaveItem[] items;

    Queue<WaveItem> queue = new Queue<WaveItem>();
    float lastSpawnTime;

    //开始出兵
    public void StartSpawn()
    {
        for (int i = 0; i < items.Length; i++)
        {
            queue.Enqueue(items[i]);
        }
        lastSpawnTime = Time.time;
    }

    public bool FinishSpawn()
    {
        return queue.Count == 0;
    }

    //更新本波次出兵
	public void UpdateSpawn () {

        if(queue.Count>0)
        {
            WaveItem item = queue.Peek();//返回队列第一个，但是不出队列
            if (Time.time - lastSpawnTime > item.interval)
            {
                lastSpawnTime = Time.time;//重置时间
                queue.Dequeue();//把敌人推出队列，开始判断第二个

                EnemyFactory.CreateEnemy(item);
            }
        }
       
	}
}
